package com.example.memohehang.controller;

import com.example.memohehang.common.R;
import com.example.memohehang.domain.Notes;
import com.example.memohehang.service.NotesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/note")
public class NotesController {
    @Autowired
    private NotesService notesService;


    // 添加
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody Notes notes)
    {
        System.out.println("添加备忘录：" + notes);
        return notesService.addNote(notes);
    }


    // 根据noteid查询对应的note
    @RequestMapping ("/selectByNote/{noteid}")
    @ResponseBody
    public R selectByNote(@PathVariable("noteid") Integer noteid)
    {

        return notesService.selectByNote(noteid);
    }

    // 查询 只显示用户自己的
    @RequestMapping ("/selectAllByUserID/{userid}")
    @ResponseBody
    public R selectAllById(@PathVariable("userid") Integer userid,@RequestParam(defaultValue = "1") Integer currentPage)
    {
        return notesService.selectAllById(userid,currentPage);
    }

    // 查询最近即将截止的未完成的备忘录的时间差
    @RequestMapping ("/selectTime/{userid}")
    @ResponseBody
    public R selectcutDownTime(@PathVariable("userid") Integer userid)
    {
        return notesService.selectcutDownTime(userid);
    }



    // 分类查询
    @RequestMapping ("/selectByType/{userid}/{type}/{isFinish}")
    @ResponseBody
    public R selectByType(@PathVariable("userid") Integer userid, @PathVariable("type") Integer type,@PathVariable("isFinish") Integer isFinish,@RequestParam(defaultValue = "1") Integer currentPage)
    {

        return notesService.selectByType(userid,type,isFinish,currentPage);

    }


    // 修改
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody Notes notes)
    {
        return notesService.update(notes);
    }

    // 删除
    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public R delete(@PathVariable("id") Integer id)
    {
        return notesService.delete(id);
    }



}


